<?php 

	session_start();
	$select = $_POST['select'];
	$user = $_SESSION['userId'];
	
    $con = mysql_connect("localhost", "group5", "group5");
	
    if(!$con)
    {
        echo "Connection Failed!";
        exit;
    }
	
    mysql_select_db("group5");
	
	if(isset($select))
	{
			$delete = "delete from USER_WORKSHOP where userId='$user' and workshopSessionId='$select';";
			mysql_query($delete, $con);
			
			//User info for email
			$userInfo = "select * from USERS where userId = $user";
			$userResult = mysql_query($userInfo);
			while($userRow = mysql_fetch_row($userResult))
			{
				$fName = $userRow[1];
				$lName = $userRow[2];
				$email = $userRow[3];
				$userName = $fName . " " . $lName;
			}
			
			//Workshop info for email
			$wsInfo = "select * from WORKSHOP as WS join WORKSHOP_SESSIONS as WSS on WSS.workshopId = WS.workshopId where WSS.workshopSessionId = $select";
			$wsResult = mysql_query($wsInfo);
			while($wsRow = mysql_fetch_row($wsResult))
			{
				$title = $wsRow[1];
				$time = $wsRow[5];
				$day = $wsRow[6];
			}
			
			echo "name: $userName email: $email title: $title time: $time day: $day";
			$to = $email;
			$subject = 'CIRT Workshop Cancelation';
			$message = "Dear $fName,\r\rYou have been removed from the roster for the workshop '$title' on $day at $time.\r\rThank you, and have a wonderful day,\rGroup5";
			$headers = 'From: webmaster@fake.com'. '\r\n' . 'Reply-to: webmaster@fake.com' . '\r\n' . 'X-Mailer: PHP/' . phpversion();
			mail($to, $subject, $message);
			header("Location:viewSessions.php?delMsg=Session Unregistered.");
	}
	else
	{
		header("Location:viewSessions.php");
	}




?>